package com.sc.nft.entity.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sc.nft.entity.dto.ProductFirstDTO;
import com.sc.nft.entity.dto.RushBuyDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class BlindBoxDetailsVO {

    @ApiModelProperty("商品id")
    private Long productId;

    @ApiModelProperty("一级标题")
    private String firstTitle;

    @ApiModelProperty("二级标题")
    private String secondTitle;

    @ApiModelProperty("缩略图")
    private String creationContent;

    @ApiModelProperty("售卖价格")
    private String productNum;

    @ApiModelProperty("积分价格")
    private String integralNum;

    @ApiModelProperty("消耗兑换券数量")
    private Integer voucherNum;

    @ApiModelProperty("用户持有兑换券数量")
    private Integer userVoucherNum;

    @ApiModelProperty("关于盲盒")
    private String productPresentation;

    @ApiModelProperty("作者昵称")
    private String nickName;

    @ApiModelProperty("作者头像")
    private String creatorAvatarImg;

    @ApiModelProperty("系列介绍")
    private String catenaPresentation;

    @ApiModelProperty("开始时间")
    private String beginTime;

    @ApiModelProperty("是否售罄 0:否 1:是")
    private Boolean isSoldOut;

    @ApiModelProperty("是否开启购买 0:否 1:是")
    private Boolean isEnable;

    @ApiModelProperty("可出售数量")
    private Integer laveNum;

    @ApiModelProperty("售卖数量")
    private Integer productCount;

    @ApiModelProperty("商品状态:  1:立即购买 2:立即抢购 3:已售罄啦 4:暂未开始")
    private Integer productType;

    @ApiModelProperty("盲盒详情图片")
    private String boxDetailsPicture;

    @ApiModelProperty("关于盲盒")
    private String aboutBox;

    @ApiModelProperty("3D模型贴图")
    private String modelImg;
    @ApiModelProperty("3D模型距离")
    private String modelDistance;

    @ApiModelProperty("作品描述")
    private List<BoxDigitalCollectionVO> list;
    @ApiModelProperty("剩余优先购买次数")
    private Integer firstTime;

    @ApiModelProperty("是否可以优先购买")
    private Boolean firstPay;

    @ApiModelProperty("苹果应用商店id")
    private String AppleProductId;
    @ApiModelProperty("分享的商品链接")
    private String productShareUrl;

    @ApiModelProperty("商品限购数量")
    private Integer upperLimit;

    @ApiModelProperty("系列名称")
    private String catenaName;

    @ApiModelProperty("购买须知")
    private String purchaseNotes;

    @ApiModelProperty("优先购权益列表")
    private List<ProductFirstDTO> firstDTOS;

    @ApiModelProperty("详情页图")
    private String productDetailPicture;
    @ApiModelProperty("详情页图类型 1 图片 2:动图 3:3d模型")
    private Integer productDetailPictureType;
    @ApiModelProperty("道具名称")
    private String propsName;
    @ApiModelProperty("优先抢权益列表")
    private List<RushBuyDTO> rushBuyDTOS;

    @ApiModelProperty("当前用户剩余优先抢次数")
    private Integer rushBuyNum;

    @ApiModelProperty("是否可以优先抢")
    private Boolean isRushBuy;

    @ApiModelProperty("3d模型id")
    private String threeModelId;

    @ApiModelProperty("发行方名称")
    private String daoName;
    @ApiModelProperty("是否锁仓")
    private Boolean isLockedPosition;

    @ApiModelProperty("锁仓描述")
    private String lockedPositionDescribe;

    @ApiModelProperty("锁仓类型 0:省缺 1:时间模式 2:日期形式 时间模式是获取藏品后延后多久,日期形式是统一锁到对应的时间")
    private Integer lockedPositionType;

    @ApiModelProperty("锁仓市场小时")
    @JsonIgnore
    private Integer lockedPositionHour;

    @ApiModelProperty("锁仓到期日期")
//    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonIgnore
    private Date lockedPositionTime;


    @ApiModelProperty(value = "剩余可兑换数量")
    private Integer surplusCount;

    @ApiModelProperty(value = "已兑换数量")
    private Integer redeemedQuantity;

    @ApiModelProperty(value = "当前时间是否允许兑换(0-未开始，1-可兑换，2-已结束)")
    private Integer redeem;

    @ApiModelProperty("是否开启注册时间限制")
    private Boolean isRegisterTime;

    @ApiModelProperty("注册开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerBeginTime;

    @ApiModelProperty("注册结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerEndTime;

    @ApiModelProperty("是否符合注册时间")
    private Boolean isConforRegisterTime=Boolean.FALSE;

    /**
     * 抢购时间
     */
    private Date buyBeginTime;
    /**
     * 结束时间
     */
    private Date endTime;


    public void setSurplusCount() {
        if (null != upperLimit && null != redeemedQuantity) {
            //计算剩余可兑换数量
            this.surplusCount = Math.max(upperLimit - redeemedQuantity, 0);
            //剩余可兑换数量与总数量比较 计算结果为真实剩余可兑换数量
//            this.surplusCount = Math.min(laveNum, surplusCount);
        } else {
            this.surplusCount = upperLimit;
        }

    }

    public void setLockedPositionDescribe() {
        // 在是锁仓的情况下,根据类型进行描述
        if (this.isLockedPosition) {
            // 时间模式
            if (this.lockedPositionType.equals(1)) {
                if (this.lockedPositionHour != null) {
                    // 当时间不为空的时候,那么要把时间/24  把他变成几天几小时
                    int day = this.lockedPositionHour / 24;
                    int hour = this.lockedPositionHour % 24;
                    if (day > 0 && hour > 0) {
                        this.lockedPositionDescribe = StrUtil.format("冷却时间: {}天{}小时", day, hour);
                    } else if (day > 0 && hour == 0) {
                        this.lockedPositionDescribe = StrUtil.format("冷却时间: {}天", day);
                    } else if (day == 0 && hour > 0) {
                        this.lockedPositionDescribe = StrUtil.format("冷却时间: {}小时", hour);
                    }
                }
            }
            if (this.lockedPositionType.equals(2)) {
                if (this.lockedPositionTime != null) {
                    // 如果当前时间大于锁仓截止时间.那么就把是否锁仓设置为false
                    if (this.lockedPositionTime.getTime() < System.currentTimeMillis()) {
                        this.isLockedPosition = false;
                        this.lockedPositionDescribe = "冷却已到期";
                    } else {
                        this.lockedPositionDescribe = StrUtil.format("冷却结束时间: {}", DateUtil.format(this.lockedPositionTime, "yyyy-MM-dd HH:mm:ss"));
                    }
                }
            }
        }
    }
}
